<?php
declare (strict_types = 1);
// 应用公共文件
/**
 * 跨域请求头
 */
function headers()
{
    return [
        'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, accesslogin',
        // 'Access-Control-Allow-Origin' => '*'
    ];
}

/**
 * 失败【抛出异常】
 */
function exceptionJson($message = '失败', $code = 40000, $data = [])
{
    $json = [
        'code'    => $code,
        'message' => $message,
        'data'    => $data
    ];

    return json($json);
}

/**
 * 失败【验证失败】
 */
function validateJson($data = [], $message = '失败', $code = 50000)
{
    $json = [
        'code'    => $code,
        'message' => $message,
        'data'    => $data
    ];

    return json($json);
}

/**
 * 成功
 */
function successJson($data = [], $message = '成功', $code = 20000)
{
    $json = [
        'code'    => $code,
        'message' => $message,
        'data'    => $data
    ];

    return json($json);
}

/**
 * 抛出异常
 */
function exception($message = '系统繁忙请稍后再试', $code = 90000)
{
    throw new \think\Exception($message, $code);
}
